package com.matrix.framework.sysconfig.iplist.data;

import com.matrix.framework.core.annotation.validation.Length;
import com.matrix.framework.core.annotation.validation.Required;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

/**
 * IP安全规则数据模型
 *
 * Copyright © 海平面工作室 版权所有
 *
 * @Author: Leo
 * @Create: 2024/12/1 15:30
 * @Since 1.2
 */
@Table(name = "security_ip_rule")
public class IpSecurityRulePo {

    @Id
    private Long id;

    @Required
    @Length(max = 50)
    private String name;

    @Required
    @Length(max = 50)
    private String ipPattern; // IP模式：单个IP、IP段、CIDR

    @Required
    @Length(max = 20)
    private String ruleType; // 规则类型：WHITELIST, BLACKLIST, RATE_LIMIT

    @Length(max = 20)
    private String targetType; // 目标类型：GLOBAL, USER, API

    @Length(max = 50)
    private String targetValue; // 目标值：用户ID、API路径等

    @Length(max = 200)
    private String description; // 规则描述

    private Integer maxRequestsPerMinute; // 每分钟最大请求数（用于频率限制）

    private Integer maxRequestsPerHour; // 每小时最大请求数

    private Integer maxRequestsPerDay; // 每天最大请求数

    @Length(max = 20)
    private String action; // 动作：ALLOW, DENY, BLOCK, LOG

    private Boolean enabled = true; // 是否启用

    private Long createTime = System.currentTimeMillis();

    private Long updateTime = System.currentTimeMillis();

    // Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIpPattern() {
        return ipPattern;
    }

    public void setIpPattern(String ipPattern) {
        this.ipPattern = ipPattern;
    }

    public String getRuleType() {
        return ruleType;
    }

    public void setRuleType(String ruleType) {
        this.ruleType = ruleType;
    }

    public String getTargetType() {
        return targetType;
    }

    public void setTargetType(String targetType) {
        this.targetType = targetType;
    }

    public String getTargetValue() {
        return targetValue;
    }

    public void setTargetValue(String targetValue) {
        this.targetValue = targetValue;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getMaxRequestsPerMinute() {
        return maxRequestsPerMinute;
    }

    public void setMaxRequestsPerMinute(Integer maxRequestsPerMinute) {
        this.maxRequestsPerMinute = maxRequestsPerMinute;
    }

    public Integer getMaxRequestsPerHour() {
        return maxRequestsPerHour;
    }

    public void setMaxRequestsPerHour(Integer maxRequestsPerHour) {
        this.maxRequestsPerHour = maxRequestsPerHour;
    }

    public Integer getMaxRequestsPerDay() {
        return maxRequestsPerDay;
    }

    public void setMaxRequestsPerDay(Integer maxRequestsPerDay) {
        this.maxRequestsPerDay = maxRequestsPerDay;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "IP黑白名单或速率规则{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", ipPattern='" + ipPattern + '\'' +
                ", ruleType='" + ruleType + '\'' +
                ", targetType='" + targetType + '\'' +
                ", targetValue='" + targetValue + '\'' +
                ", description='" + description + '\'' +
                ", maxRequestsPerMinute=" + maxRequestsPerMinute +
                ", maxRequestsPerHour=" + maxRequestsPerHour +
                ", maxRequestsPerDay=" + maxRequestsPerDay +
                ", action='" + action + '\'' +
                ", enabled=" + enabled +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                '}';
    }
}